<template>
  <div class="timeline-container">
    <h2 v-if="title" class="timeline-title">{{ title }}</h2>
    
    <div class="timeline" :class="{ 'alternate': alternate }">
      <div
        v-for="(item, index) in items"
        :key="index"
        class="timeline-item"
        :class="{ 'left': alternate && index % 2 === 0, 'right': alternate && index % 2 !== 0 }"
      >
        <div v-if="alternate" class="timeline-dot"></div>
        <div class="timeline-card">
          <div v-if="!alternate" class="timeline-dot"></div>
          <div class="timeline-date">{{ item.date }}</div>
          <div class="timeline-content">
            <h3 v-if="item.title" class="item-title">{{ item.title }}</h3>
            <p class="item-description">{{ item.description }}</p>
            <div v-if="item.image" class="item-image">
              <img :src="item.image" :alt="item.title || item.date" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Timeline',
  props: {
    title: {
      type: String,
      default: ''
    },
    items: {
      type: Array,
      required: true,
      default: () => []
    },
    alternate: {
      type: Boolean,
      default: true
    }
  }
}
</script>

<style lang="scss" scoped>
.timeline-container {
  position: relative;
  padding: 20px 0;
  
  .timeline-title {
    text-align: center;
    margin-bottom: 40px;
    font-size: 28px;
    position: relative;
    
    &::after {
      content: '';
      position: absolute;
      bottom: -10px;
      left: 50%;
      transform: translateX(-50%);
      width: 50px;
      height: 3px;
      background-color: var(--primary-color);
    }
  }
  
  .timeline {
    position: relative;
    max-width: 1140px;
    margin: 0 auto;
    
    &::before {
      content: '';
      position: absolute;
      width: 2px;
      background-color: #f0f0f0;
      top: 0;
      bottom: 0;
      margin-left: -1px;
    }
    
    &.alternate::before {
      left: 50%;
    }
    
    &:not(.alternate)::before {
      left: 20px;
    }
  }
  
  .timeline-item {
    position: relative;
    margin-bottom: 40px;
    
    &:last-child {
      margin-bottom: 0;
    }
    
    &.left {
      padding-right: calc(50% + 30px);
      
      .timeline-card {
        text-align: right;
      }
    }
    
    &.right {
      padding-left: calc(50% + 30px);
    }
  }
  
  .timeline-dot {
    position: absolute;
    width: 20px;
    height: 20px;
    background-color: var(--primary-color);
    border-radius: 50%;
    z-index: 1;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    border: 3px solid #fff;
  }
  
  .alternate .timeline-dot {
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
  }
  
  .timeline-card {
    padding: 15px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
    position: relative;
    
    &:not(.alternate) {
      margin-left: 40px;
      
      .timeline-dot {
        left: -30px;
        top: 15px;
      }
    }
  }
  
  .timeline-date {
    color: var(--primary-color);
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 16px;
  }
  
  .timeline-content {
    .item-title {
      font-size: 18px;
      margin-bottom: 10px;
    }
    
    .item-description {
      color: var(--text-light-color);
      line-height: 1.6;
    }
    
    .item-image {
      margin-top: 15px;
      border-radius: 6px;
      overflow: hidden;
      
      img {
        width: 100%;
        display: block;
      }
    }
  }
}

@media (max-width: 768px) {
  .timeline-container {
    .timeline {
      &.alternate::before {
        left: 20px;
      }
      
      .timeline-item {
        &.left, &.right {
          padding-right: 0;
          padding-left: 40px;
          
          .timeline-card {
            text-align: left;
          }
          
          .timeline-dot {
            left: 10px;
            transform: none;
          }
        }
      }
    }
  }
}
</style> 